//
//  SL_DataController.swift
//  SWIFT_LEARN
//
//  Created by youxin on 2018/1/15.
//  Copyright © 2018年 YST. All rights reserved.
//

import UIKit

class SL_DataController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    
    
    let tabview : UITableView = UITableView(frame:UIScreen.main.bounds, style:UITableViewStyle.plain)
    var dataArr : NSArray = NSArray()
    var urlArr : NSArray  = NSArray()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    self.creatUI()
    }
    
    func creatUI() {
        
        dataArr = ["百度","航哥swift","33"];
        urlArr = ["http://www.baidu.com","http://www.hangge.com/blog/cache/category_72_1.html","http://www.baidu.com"]
        
        
        self.view.addSubview(tabview)
        tabview.dataSource = self
        tabview.delegate = self
        tabview.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: "cell")
        
        
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArr.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell:UITableViewCell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
        
        cell.textLabel?.text = dataArr[indexPath.row] as? String
        
        return cell
        
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        let webVC = Da_WebController()
        webVC.utlStr = urlArr[indexPath.row] as! NSString
        webVC.titleStr = (dataArr[indexPath.row] as? String)! 
        self.navigationController?.pushViewController(webVC, animated: true)
        
    }
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
